import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
const $time 	= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '条码号',		name: 'spec_code' },
			{ label: '实验号',		name: 'experiment_num' },
			{ label: '自然项目',		name: 'kind_id',				type:'select', 		loading:true},
			{ label: '送检医院',		name: 'hosp_id',				type:'select', 		loading:true},
			{ label: '科室',		name: 'team_id',				type:'select', 		loading:true, idStr:'uuid'},
			{ label: '岗位',		name: 'job_id',				type:'select', 		loading:true},
			{ label: '接收时间',		names: ['start_receive_time','end_receive_time'], name:'jz-time', type:'date-range', 	loading:true },
		],
	}
	
	componentDidMount(){
		this.getSelect()
		// 添加默认时间 20220509 耿琰
		$time.then(f=>{
			const arr = f.duration['1']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 项目 
			// 单一项目改自然项目  20220509 耿琰
			$fn.setRow( forms, 'kind_id', await f.getCache({ api:'nature_project' }) )
			// 医院
			$fn.setRow( forms, 'hosp_id', await f.getCache({ api:'hospital' }) )
			// 科室
			$fn.setRow( forms, 'team_id', await f.getCache({ api:'ke_shi' }) )
			// 岗位
			this.resetData = await f.getCache({ api:'gang_wei' })
			$fn.setRow( forms, 'job_id', this.resetData )
			
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'receive/getReceiveLists', {isIndex:true} )
	
	// 表单
	cols = [
		{ title: '标本条码号', 	dataIndex: 'spec_code', 			...$fn.table.spec_code },
		{ title: '实验号', 		dataIndex: 'lb_tpl', 				...$fn.table.spec_code, 	sorter:true, },
		{ title: '自然项目', 	dataIndex: 'kind_name', 		width:200 },
		{ title: '项目列表', 	dataIndex: 'kind_list', 		width:120 },
		{ title: '姓名', 		dataIndex: 'patient_name', 			...$fn.table.name },
		{ title: '性别', 		dataIndex: 'sex_name',  			...$fn.table.sex},
		{ title: '年龄', 		dataIndex: 'age_first_val', 		...$fn.table.age},
		{ title: '岗位', 		dataIndex: 'job_id', 			width:150},
		{ title: '科室', 		dataIndex: 'team_name', 		width:150},
		{ title: '送检医院', 	dataIndex: 'hosp_name',  			width:200 },
		{ title: '接收时间', 	dataIndex: 'sp_receive_time',  		...$fn.table.time},
	]
	
	// 操作按钮
	controls = () => {
		return [
			Controls.exports.call(this,'receive/getReceiveLists',{isSock: true})
		]
	}
	
	render(){
		return (
			<Page title='标本领取清单'  controls={this.controls()}>
				{/* 搜索 */}
				{ SearchForm.call(this,{timeStr:'1'}) }
				{/* 表格 */}
				{ Table.call(this, {isIndex:true, isInit: window.isInit}) }
			</Page>
		)
	}
}

export default Index